<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>添加老师信息</title>
<link rel="stylesheet" href="../../../css/radio/style.css">

<link rel="stylesheet" href="../../../css/Semantic/semantic.min.css" />
<link rel="stylesheet" href="../../../layui/css/layui.css" media="all">
<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
<script src="../../../layui/layui.js"></script>
<script src="../../../js/vue/vue.js"></script>
<script src="../../../js/vue/axios.min.js"></script>


<style type="text/css">
.zth-container {
	margin-top: 40px;
	margin-left: 30%;
	padding-bottom: 50px;
	width: 350px;
}

.zth-container-but {
	text-align: center;
	margin-top: 20px;
	margin-left: 10px;
}

.layui-form-label {
	width: auto;
}
</style>
</head>
<body>
	<div id="app">
		<div class="zth-container">
			<div class="layui-form-item">
				<label class="layui-form-label" style="width: auto;">职务名</label>
				<div class="layui-input-block">
					<input type="text" v-model="position_name" name="position_name" lay-verify="title"
						autocomplete="off" placeholder="请输入职务名" class="layui-input">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">管理范围</label>
				<div class="layui-input-block">
					<textarea placeholder="请输入内容" v-model="position_thing" class="layui-textarea"></textarea>
				</div>
			</div>

			<div class="zth-container-but">
				<button type="button" class="layui-btn" @click="edit">提交</button>
				<button type="button" class="layui-btn layui-btn-primary" id="close"
					onclick="close()">关闭</button>
			</div>
		</div>
	</div>
	<script src="../../../js/jquery.min.js"></script>
	<script type="text/javascript">
	//截取id
	var href=location.href;
	var index=href.indexOf("=");
	var sub=href.substr(index+1,href.length);
	console.log(sub);
	var vm=new Vue({
		el:'#app',
		data(){
			return{
				tpos_id:sub,//职务id
				position_name:'',//职务名
				position_thing:'',//管理范围
				
			}
		},
		mounted:function(){
			this.tposShow();
		},
		methods:{
			edit:function(){
				//特殊字符
				  var flag = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>《》/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？ ]");
				//中文
				  var patrn=/[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/gi; 
				//英文  
				var p = /[a-z]/i;
				 if(
						this.position_name!=''&&!flag.test(this.position_name)&&
						this.position_thing!=''&&!flag.test(this.position_thing)
				){ 
					var params =new URLSearchParams();
					params.append('tpos_id',this.tpos_id);
					params.append('position_name',this.position_name);
					params.append('position_thing',this.position_thing);
					axios.post('/tpos/edit',params).then(res=>{
						console.log(res);
						if(res.data>0){
							succeed();
						}else{
							layer.msg('失败！');
						}
						
					},err=>{
						console.log(err);
					})
				 }else{
					alert("您填写有误！");
				}  
				
			},
			tposShow:function(){
				axios.get('/tpos/findbyId?tpos_id='+sub).then(res=>{
					var o=res.data.data;
					this.position_name=o.position_name;
					this.position_thing=o.position_thing;
				},err=>{
					console.log(err);
				});
			}
			
		}
	});
	//操作成功
	function succeed() {
		layui.use(['form', 'jquery'], function() {
			layer.alert("编辑成功！", function() {
				var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
				parent.layer.close(index);
				//关闭父级页面的表格
				parent.layui.table.reload('testReload');
			});
		});
	}
	
	//关闭
	layui.use(['form', 'jquery'], function() {
		var $=layui.jquery
	  $("#close").on('click',function(){
		layui.use(['form', 'jquery'], function() {
				var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
				parent.layer.close(index);
				//关闭父级页面的表格
				parent.layui.table.reload('testReload');
		});
	});
	
	});
	
	
	layui.use(['form', 'layedit', 'laydate','upload','jquery'], function(){
		  var form = layui.form
		  ,layer = layui.layer
		  ,layedit = layui.layedit
		  ,laydate = layui.laydate
		  ,upload = layui.upload
		  ,$=layui.jquery;
		  
	});
	</script>
</body>
</html>